package com.yuncheng.spcyApi.lucene;

/*import cn.hutool.core.collection.CollectionUtil;
import com.yuncheng.spcyApi.entity.SpcyFgTk;
import com.yuncheng.spcyApi.service.ISpcyFgTkService;
import com.yuncheng.spcyApi.service.ISpcyFgZdwjService;
import lucenex.api.FgTkApi;
import lucenex.base.SpcyPage;
import lucenex.po.FgTkPo;
import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;*/

/**
 * 条款库-索引
 */
//@Component(value = "fgTkIndexService")
public class FgTkIndexService {
    /*private static final Logger log = LoggerFactory.getLogger(FgTkIndexService.class);

    static final String dataKey = "tk";
    static final String baseUrl = "D:/projectDemo/lucene/index";

    static final String[] searchKeywords = {"fzdyzh", "fzdyznr", "fjcyd"};

    @Resource
    @Lazy
    private ISpcyFgTkService spcyFgTkService;

    @Resource
    @Lazy
    private ISpcyFgZdwjService spcyFgZdwjService;

    public void inintTk(){
        List<SpcyFgTk> tkList = spcyFgTkService.list();
        this.inintTk(tkList);
    }

    public void inintTk(List<SpcyFgTk> tkList){
        if (CollectionUtil.isEmpty(tkList)) {
             return;
        }
        addIndexTkList(tkList);
    }

    public List<FgTkPo> queryList(String gjz, String zjid){

        List<FgTkPo> queryList = FgTkApi.queryList(gjz, zjid, searchKeywords);

        return queryList;
    }

    public SpcyPage<FgTkPo> queryPageList(String gjz, String zjid){
//        FgTkApi.InitIndexFile(dataKey, baseUrl);
        List<FgTkPo> queryList = FgTkApi.queryList(gjz, zjid, searchKeywords);
        return FgTkApi.queryPageList(queryList);
    }

    public void addIndexTk(SpcyFgTk fgTk){
        FgTkPo fgTkPo = new FgTkPo();

        try {
            BeanUtils.copyProperties(fgTkPo, fgTk);
        } catch (IllegalAccessException e) {
            log.error("添加条款索引出错[IllegalAccessException]：{}", e.getMessage());
        } catch (InvocationTargetException e) {
            log.error("添加条款索引出错[InvocationTargetException]：{}", e.getMessage());
        }

//        FgTkApi.InitIndexFile(dataKey, baseUrl);
        FgTkApi.AddIndexData(fgTkPo);
    }

    public void addIndexTkList(List<SpcyFgTk> tkList){
        List<FgTkPo> fgTkPoList = new ArrayList<>();

        tkList.forEach(item -> {
            FgTkPo fgTkPo = new FgTkPo();
            try {
                BeanUtils.copyProperties(fgTkPo, item);
            } catch (IllegalAccessException e) {
                log.error("添加条款索引出错[IllegalAccessException]：{}", e.getMessage());
            } catch (InvocationTargetException e) {
                log.error("添加条款索引出错[InvocationTargetException]：{}", e.getMessage());
            }
            fgTkPoList.add(fgTkPo);
        });

//        FgTkApi.InitIndexFile(dataKey, baseUrl);
        FgTkApi.AddIndexData(fgTkPoList);
    }

    public void deleteAllIndexTk(){
//        FgTkApi.InitIndexFile(dataKey, baseUrl);
        FgTkApi.deleteAllIndexData(dataKey);
    }

    public void deleteAllIndexTkById(String id){
//        FgTkApi.InitIndexFile(dataKey, baseUrl);
        FgTkApi.deleteIndexDataById(dataKey, id);

       *//* try {
            deleteIndex(id);
        } catch (Exception e) {
            e.printStackTrace();
        }*//*
    }

    public void deleteAllIndexTkById2(String id){
//        FgTkApi.InitIndexFile(dataKey, baseUrl);
        FgTkApi.deleteIndexDataById2(dataKey, id);
    }
*/
}
